/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { LogCollector } from '../../../../../src/base/internal/pool/log-collection/log-collector';
import { ScheduleLog, WorkLog } from '../../../../../src/base/internal/pool/log-collection/log';
import { LogType } from '../../../../../src/base/internal/pool/enum/log-type';

describe('test log collector', () => {
  const workLogCollector = new LogCollector<WorkLog>();
  const scheduleLogCollector = new LogCollector<ScheduleLog>();
  test('test add', () => {
    const workLog: WorkLog = {
      type: LogType.WORK,
      time: '',
      workerId: 0,
      content: '',
      taskPath: '',
      taskName: '',
      taskCompletePath: ''
    };
    workLogCollector.add(workLog);
    expect(workLogCollector.dump().size === 1).toBeTruthy();
    const scheduleLog: ScheduleLog = {
      type: LogType.SCHEDULE,
      time: '',
      workerId: 0,
      workId: ''
    };
    scheduleLogCollector.add(scheduleLog);
    expect(scheduleLogCollector.dump().size === 1).toBeTruthy();
  });

  test('test dump', () => {
    const workLog = workLogCollector.dump().values().next().value;
    expect(workLog.type === LogType.WORK && workLog.time === '').toBeTruthy();
    const scheduleLog = scheduleLogCollector.dump().values().next().value;
    expect(scheduleLog.type === LogType.SCHEDULE && scheduleLog.time === '').toBeTruthy();
  });

  test('test clear', () => {
    workLogCollector.clear();
    expect(workLogCollector.dump().size === 0).toBeTruthy();
    scheduleLogCollector.clear();
    expect(scheduleLogCollector.dump().size === 0).toBeTruthy();
  });
});
